require(["jquery","bbcare",
        "scprit/department/vm/assessmentScreening/temperamentAssessment.ui.js",
        "scprit/department/vm/assessmentScreening/assessmentScreeningQuestion.servers.js",
        "scprit/department/vm/assessmentScreening/temperamentAssessment.event.js"],
    function ($,$bb,$ui,$servers,$event) {
        var getParams = $bb.getPageParams();
        var type = getParams.type;
        var userId = getParams.userId;
        var answerId = getParams.answerId;
        //问卷题目获取：
        var paramsQuestion = $servers.getParams(type,userId);
        if(answerId){paramsQuestion = $servers.getParamsTem(type,userId,getParams.testTime)}
        //患者信息展示：
        var infoParams = $servers.infoParams(userId);
        var infoFn = function(dt){
            //基本信息渲染：
            dt= dt.data;
            var testDate = $servers.getNowFormatDate();
            if(answerId){testDate = getParams.testTime;}
            var diff = $servers.dateDiff(dt.PatientInfo.birthday,testDate);
            var monthAge = $servers.age(diff,dt.PatientInfo.pregnancyDay);
            dt.PatientInfo.monthAge = monthAge;
            dt.PatientInfo.testDate = testDate;
            $ui.basicInfoInit({"id":"#basic-info","data":dt.PatientInfo});
            var quesFn = function(data){
                var scoreObj = {};
                data = $event.dataSheet(data.data);
                data = $event.dataDeal(data);
                if(answerId){
                    scoreObj = JSON.parse(getParams.answer.answerResult).map;
                    data = $event.historyDeal(data,scoreObj);
                }
                $ui.temperamentInit({"id":"#question","data":data});
                $ui.subjectInit({"id":"#subject","data":data});
                var sH = $("#subject-height").height();
                $("#subject-title").css("height",(sH-5)+"px");
                if(!answerId){
                    $event.scoreCheck(data,scoreObj);
                    $event.submitScore(data,scoreObj,type,userId);
                }
                if(answerId){
                    $event.viewResult(userId,answerId,type);
                    $event.quesClick();
                    $event.subjectClick(data);
                    $("#question").find('ul[class*="ques-checked"]').click();
                }
            };
            $servers.getQuestion(paramsQuestion,quesFn);
        };
        $servers.getInfo(infoParams,infoFn);

    });